(() => {

    'use strict';
    goog.provide('Blockly.Blocks.ruilong');
    goog.require('Blockly.Blocks');
    goog.require('path');

    const mediaDirPath = path.join(document.currentScript.src, '../../media/');

    Blockly.Msg['RUILONG_HUE'] = 120;


    //按钮传感器
    Blockly.Blocks.ruilong_button = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("按钮传感器");
            //.appendField(new Blockly.FieldImage(mediaDirPath + "/ruilong/RLSEB405BS.png", 40, 40));
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setOutput(true, Boolean);
            this.setInputsInline(true);
            this.setTooltip('');
        }
    };
    //磁敏传感器
    Blockly.Blocks.ruilong_magnetic = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("磁敏传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setOutput(true, Boolean);
            this.setInputsInline(true);
            this.setTooltip('');
        }
    };
    //热释电传感器
    Blockly.Blocks.ruilong_pir = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("热释电传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setOutput(true, Boolean);
            this.setInputsInline(true);
            this.setTooltip('');
        }
    };
    //红外测障传感器
    Blockly.Blocks.ruilong_obstacle = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("红外测障传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //震动传感器
    Blockly.Blocks.ruilong_vibration = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("震动传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setOutput(true, Boolean);
            this.setInputsInline(true);
            this.setTooltip('');
        }
    };
    //单向倾角传感器
    Blockly.Blocks.ruilong_tilt = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("单向倾角传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setOutput(true, Boolean);
            this.setInputsInline(true);
            this.setTooltip('');
        }
    };
    //触摸传感器
    Blockly.Blocks.ruilong_touch = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("触摸传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setOutput(true, Boolean);
            this.setInputsInline(true);
            this.setTooltip('');
        }
    };
    //碰撞传感器
    Blockly.Blocks.ruilong_collision = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("碰撞传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setOutput(true, Boolean);
            this.setInputsInline(true);
            this.setTooltip('');
        }
    };

    //DHT11温湿度传感器
    Blockly.Blocks.ruilong_dht11 = {
        init: function () {
            var WHAT = [[Blockly.Msg.MIXLY_DHT11_T, 'temperature'], [Blockly.Msg.MIXLY_DHT11_H, 'humidity']];
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("DHT11温湿度传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.appendDummyInput("").appendField(new Blockly.FieldDropdown(WHAT), "WHAT");
            this.setOutput(true, Number);
        }
    };
    //超声波测距传感器
    Blockly.Blocks.ruilong_hc_sr04 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("超声波测距");
            this.appendValueInput("PIN1", Number).setCheck(Number).setAlign(Blockly.ALIGN_RIGHT).appendField("Trig#")
            this.appendValueInput("PIN2", Number).setCheck(Number).setAlign(Blockly.ALIGN_RIGHT).appendField("Echo#");
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //超声波测距传感器
    Blockly.Blocks.ruilong_hc_sr04_3p = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("超声波测距 3P");
            this.appendValueInput("PIN", Number).setCheck(Number).setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.MIXLY_PIN);
            this.setInputsInline(true);
            this.setOutput(true, Number);
            this.setTooltip('');
        }
    };
    //自锁按钮传感器
    Blockly.Blocks.ruilong_switch = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("自锁按钮传感器");
            this.appendValueInput("PIN", Number).appendField(Blockly.Msg.MIXLY_PIN).setCheck(Number);
            this.setOutput(true, Boolean);
            this.setInputsInline(true);
            this.setTooltip('');
        }
    };
    //DS18B20温度传感器
    Blockly.Blocks.ruilong_ds18B20 = {
        init: function () {
            var UNIT = [[Blockly.Msg.MIXLY_DS18B20_C, '0'], [Blockly.Msg.MIXLY_DS18B20_F, '1']];
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendValueInput("PIN", Number).appendField("DS18B20温度传感器").setCheck(Number);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_DS18B20_GET_TEMP).appendField(new Blockly.FieldDropdown(UNIT), "UNIT");
            this.setOutput(true, Number);
        }
    };
    //SHT20温湿度传感器
    Blockly.Blocks.ruilong_SHT20 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("SHT20温湿度传感器")
            this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT).appendField(new Blockly.FieldDropdown([["温度(℃)", "sht20.readTemperature()"], ["湿度(%)", "sht20.readHumidity()"]]), "SHT20_TYPE");
            this.setInputsInline(true);
            this.setOutput(true);
            this.setTooltip();
        }
    };

    //AHT20/21温湿度传感器
    Blockly.Blocks.ruilong_AHT20_21 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("AHT20/21温湿度传感器")
            this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT)
            .appendField(new Blockly.FieldDropdown([["温度(℃)", "aht20.readTemperature()"], 
                                                    ["湿度(%)", "aht20.readHumidity()"]]), "AHT21_TYPE");
            this.setInputsInline(true);
            this.setOutput(true);
            this.setTooltip();
        }
    };

    //BMP280温度气压传感器
    Blockly.Blocks.ruilong_BMP280 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("BMP280温度气压传感器");
            this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT)
                .appendField(new Blockly.FieldDropdown([["温度(℃)", "bmp.readTemperature()"], ["气压(pa)", "bmp.readPressure()"], ["高度(m))", "bmp.readAltitude()"]]), "BMP280_TYPE");
            this.setInputsInline(true);
            this.setOutput(true);
            this.setTooltip();
        }
    };
    //H203B温度气压传感器
    Blockly.Blocks.ruilong_H203B = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("H203B温度气压传感器");
            this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT)
                .appendField(new Blockly.FieldDropdown([["温度(℃)", "myHP203.readTemperature()"], 
                                                        ["气压(pa)", "myHP203.readPressure()"], 
                                                        ["高度(m))", "myHP203.readAltitude()"]]), "H203B_TYPE");
            this.setInputsInline(true);
            this.setOutput(true);
            this.setTooltip();
        }
    };
    //16键触摸键盘模块
    Blockly.Blocks.ruilong_16CHTOUCH = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("")
                .appendField("获取 16键触摸键盘模块")
                .appendField(new Blockly.FieldDropdown([["0", "Key_0"], 
                ["1", "Key_1"],
                ["2", "Key_2"],
                ["3", "Key_3"],
                ["4", "Key_4"],
                ["5", "Key_5"],
                ["6", "Key_6"],
                ["7", "Key_7"],
                ["8", "Key_8"],
                ["9", "Key_9"],
                ["A", "Key_A"],
                ["B", "Key_B"],
                ["C", "Key_C"],
                ["D", "Key_D"],
                ["#", "Key_j"],
                ["*", "Key_x"]]),'KEY_ID')
                .appendField("状态");
            this.setOutput(true, Boolean);
            this.setInputsInline(true);
            this.setTooltip('');
        }
    };
    //16键触摸键盘模块 方向+功能键
    Blockly.Blocks.ruilong_16CHTOUCH_KJ = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("")
                .appendField("获取 16键触摸键盘模块 方向+功能键")
                .appendField(new Blockly.FieldDropdown([["0", "0x01"], 
                ["1", "0x02"],
                ["2", "0x04"],
                ["3", "0x08"],
                ["4", "0x10"],
                ["5", "0x20"],
                ["6", "0x40"],
                ["7", "0x80"],
                ["8", "0x0100"],
                ["9", "0x0200"],
                ["10", "0x0400"],
                ["11", "0x0800"],
                ["12", "0x1000"],
                ["13", "0x2000"],
                ["14", "0x4000"],
                ["15", "0x8000"]]),'KEY_ID')
                .appendField("状态");
            this.setOutput(true, Boolean);
            this.setInputsInline(true);
            this.setTooltip('');
        }
    };
    //BH1750数字环境光传感器
    Blockly.Blocks.ruilong_BH1750_INIT = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("BH1750数字环境光传感器 初始化");
            this.setInputsInline(true);
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
            this.setTooltip();
        }
    };
    Blockly.Blocks.ruilong_BH1750_SET = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("BH1750数字环境光传感器")
                .appendField(new Blockly.FieldDropdown([["连续模式：分辨率1 lux，耗时约120ms（默认）", "CONTINUOUS_HIGH_RES_MODE"], 
                ["连续模式：分辨率0.5 lux，耗时约120ms", "CONTINUOUS_HIGH_RES_MODE_2"],
                ["连续模式：分辨率4 lux，耗时约16ms", "CONTINUOUS_LOW_RES_MODE"],
                ["单次模式：分辨率1 lux，耗时约120ms", "ONE_TIME_HIGH_RES_MODE"],
                ["单次模式：分辨率0.5 lux，耗时约120ms", "ONE_TIME_HIGH_RES_MODE_2"],
                ["单次模式：分辨率4 lux，耗时约16ms", "ONE_TIME_LOW_RES_MODE"]]),'MODE')
                .appendField("状态");
            this.setInputsInline(true);
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
            this.setTooltip();
        }
    };
    Blockly.Blocks.ruilong_BH1750_SETMTREG = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendValueInput("TIME").appendField("BH1750数字环境光传感器 测量时间").setCheck(Number);
            this.setInputsInline(true);
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
            this.setTooltip();
        }
    };
    Blockly.Blocks.ruilong_BH1750_MTRADY = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("BH1750数字环境光传感器 测量完成？");
            this.setInputsInline(true);
            this.setOutput(true);
            this.setTooltip();
        }
    };
    Blockly.Blocks.ruilong_BH1750 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("BH1750数字环境光传感器");
            this.setInputsInline(true);
            this.setOutput(true);
            this.setTooltip();
        }
    };

    //LSM6DSM 6轴加速度陀螺仪传感器
    var ruilong_LSM6DSM_GETAB = [
        ["X轴加速度", "readFloatAccelX"],
        ["Y轴加速度", "readFloatAccelY"],
        ["Z轴加速度", "readFloatAccelZ"],
        ["X轴角速度", "readFloatGyroX"],
        ["Y轴角速度", "readFloatGyroY"],
        ["Z轴角速度", "readFloatGyroZ"],
        ["温度（℃）", "readTempC"],
        ["温度（℉）", "readTempF"]
    ];


    Blockly.Blocks.ruilong_LSM6DSM = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField('LSM6DSM');
            this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT)
                .appendField(new Blockly.FieldDropdown(ruilong_LSM6DSM_GETAB), "LSM6DSM");
            this.setInputsInline(true);
            this.setOutput(true);
            this.setTooltip();
        }
    };

    //MSA311 3轴加速度传感器
    Blockly.Blocks.ruilong_MSA311_READ = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("MSA311读取数据");
            this.setInputsInline(true);
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
            this.setTooltip();
        }
    };

    var ruilong_MSA311_GETAB = [
        ["X轴加速度", "x"],
        ["Y轴加速度", "y"],
        ["Z轴加速度", "z"]
    ];


    Blockly.Blocks.ruilong_MSA311 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField('MSA311返回数据');
            this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT)
                .appendField(new Blockly.FieldDropdown(ruilong_MSA311_GETAB), "MSA311");
            this.setInputsInline(true);
            this.setOutput(true);
            this.setTooltip();
        }
    };

    //ADXL345传感器-重力感应块-获取数据
    var ruilong_ADXL345_GETAB = [
        [Blockly.Msg.MixGo_MPU9250_AX, "accel.getAccelerationX()"],
        [Blockly.Msg.MixGo_MPU9250_AY, "accel.getAccelerationY()"],
        [Blockly.Msg.MixGo_MPU9250_AZ, "accel.getAccelerationZ()"],
        [Blockly.Msg.MixGo_MPU9250_AX + "(g)", "accel.getAccelerationX()/256.0"],
        [Blockly.Msg.MixGo_MPU9250_AY + "(g)", "accel.getAccelerationY()/256.0"],
        [Blockly.Msg.MixGo_MPU9250_AZ + "(g)", "accel.getAccelerationZ()/256.0"],
    ];


    Blockly.Blocks.ruilong_ADXL345 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField('ADXL345');
            this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT)
                .appendField(new Blockly.FieldDropdown(ruilong_ADXL345_GETAB), "ADXL345_PIN");
            this.setInputsInline(true);
            this.setOutput(true);
            this.setTooltip();
        }
    };

    Blockly.Blocks.ruilong_ADXL345_setOffset = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_SETTING).appendField('ADXL345');
            this.appendValueInput("OFFSET").setCheck(Number).appendField("偏移")
                .appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_DISPLAY_MATRIX_X, "setOffsetX"], [Blockly.Msg.MIXLY_DISPLAY_MATRIX_Y, "setOffsetY"], [Blockly.Msg.MIXLY_Z_AXIS, "setOffsetZ"]]), "MIXEPI_ADXL345_OFFSET");
            this.setInputsInline(true);
            this.setPreviousStatement(true, null);
            this.setNextStatement(true, null);
        }
    };




    //传感器-TCS34725颜色识别-获取数据
    var ruilong_TCS34725_GETRGB = [
        [Blockly.Msg.COLOUR_RGB_RED, "tcs.getRed()"],
        [Blockly.Msg.COLOUR_RGB_GREEN, "tcs.getGreen()"],
        [Blockly.Msg.COLOUR_RGB_BLUE, "tcs.getBlue()"],
    ];

    Blockly.Blocks.ruilong_TCS34725_Get_RGB = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("")
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField("读取TCS34725颜色传感器")
            .appendField(new Blockly.FieldDropdown(ruilong_TCS34725_GETRGB), "TCS34725_GETRGB")
            .appendField("的数值");
            this.setInputsInline(true);
            this.setOutput(true);
        }
    };
    //传感器-VEML6040颜色识别-获取数据
    var ruilong_VEML6040_GETRGBW = [
        ["红色", "RGBWSensor.getRed()"],
        ["绿色", "RGBWSensor.getGreen()"],
        ["蓝色", "RGBWSensor.getBlue()"],
        ["白色", "RGBWSensor.getWhite()"],
        ["环境光", "RGBWSensor.getCCT()"]
    ];

    Blockly.Blocks.ruilong_VEML6040_Get_RGBW = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("")
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField("读取VEML6040颜色传感器")
            .appendField(new Blockly.FieldDropdown(ruilong_VEML6040_GETRGBW), "VEML6040_GETRGBW")
            .appendField("的数值");
            this.setInputsInline(true);
            this.setOutput(true);
        }
    };

    //MAX3010X心率传感器
    var ruilong_MAX30102_TYPE = [
        ["温度(℃)", "particleSensor.readTemperature()"],
        ["温度(℉))", "particleSensor.readTemperatureF()"],
        ["红光", "particleSensor.getRed()"],
        ["红外光", "particleSensor.getIR()"],
        ["绿光", "particleSensor.getGreen()"],
    ];

    Blockly.Blocks.ruilong_MAX3010X_Value = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("MAX3010X心率血氧传感器");
            this.appendDummyInput("").setAlign(Blockly.ALIGN_RIGHT).appendField(new Blockly.FieldDropdown(ruilong_MAX30102_TYPE), "MAX3010X_TYPE");
            this.setInputsInline(true);
            this.setOutput(true);
            this.setTooltip();
        }
    };

    Blockly.Blocks.ruilong_MAX3010X_HR = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField(new Blockly.FieldTextInput('Bmp_value'), 'VAR').appendField("MAX3010X心率血氧传感器 心率");
            this.appendStatementInput('DO');
            this.setPreviousStatement(true);
            this.setNextStatement(true);
            this.setInputsInline(true);
            // this.setTooltip(Blockly.Msg.MIXLY_IR_RECIEVE_TOOLTIP);
        },
        getVars: function () {
            return [this.getFieldValue('VAR')];
        },
        renameVar: function (oldName, newName) {
            if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
                this.setTitleValue(newName, 'VAR');
            }
        }
    };

    //夏普PM2.5粉尘传感器(GP2Y1026AU0F)
    Blockly.Blocks.ruilong_GP2Y1026 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendValueInput("PIN", Number).appendField(new Blockly.FieldTextInput('Dust_value'), 'VAR').appendField("PM2.5粉尘传感器").setCheck(Number);
            this.appendStatementInput('DO').appendField(new Blockly.FieldImage(mediaDirPath + "/ruilong/RLSPP126GP.png", 60, 60));
            /*this.appendStatementInput('DO2')
            .appendField(Blockly.Msg.MIXLY_IR_RECEIVE_NO);*/
            this.setPreviousStatement(true);
            this.setNextStatement(true);
            this.setInputsInline(true);
            this.setTooltip(Blockly.Msg.MIXLY_IR_RECIEVE_TOOLTIP);
        },
        getVars: function () {
            return [this.getFieldValue('VAR')];
        },
        renameVar: function (oldName, newName) {
            if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
                this.setTitleValue(newName, 'VAR');
            }
        }
    };

    //MRP121触摸传感器
    var MRP121_TOUCHLIST = [["E0", "0"], ["E1", "1"], ["E2", "2"], ["E3", "3"],
    ["E4", "4"], ["E5", "5"], ["E6", "6"], ["E7", "7"],
    ["E8", "8"], ["E9", "9"], ["E10", "10"], ["E11", "11"]];

    Blockly.Blocks.ruilong_MRP121 = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("MRP121触摸传感器");
            this.appendDummyInput().appendField("如果");
            this.appendDummyInput("").appendField(new Blockly.FieldDropdown(MRP121_TOUCHLIST), 'MRP121_TOUCH');
            this.appendDummyInput("").appendField(new Blockly.FieldDropdown([["接触", "1"], ["释放", "0"]]), 'MRP121_TOUCH_STATE');
            this.setInputsInline(true);
            this.appendStatementInput('DO');
            this.setPreviousStatement(true);
            this.setNextStatement(true);
            this.setTooltip(Blockly.Msg.CONTROLS_IF_IF_TOOLTIP);
            this.setTooltip('');
        }
    };

    Blockly.Blocks.ruilong_TCA9548A = {
        init: function () {
            this.setColour(Blockly.Msg['RUILONG_HUE']);
            this.appendDummyInput("").appendField("TCA9548A I2C扩展");
            this.appendDummyInput().appendField("选择");
            this.appendDummyInput("").appendField(new Blockly.FieldDropdown([["CH0", "0"], ["CH1", "1"], ["CH2", "2"], ["CH3", "3"],
            ["CH4", "4"], ["CH5", "5"], ["CH6", "6"], ["CH7", "7"]]), 'TCA9548A_CH').appendField(" 控制");
            this.setInputsInline(true);
            this.appendStatementInput('DO');
            this.setPreviousStatement(true);
            this.setNextStatement(true);
            this.setTooltip(Blockly.Msg.CONTROLS_IF_IF_TOOLTIP);
            this.setTooltip('');
        }
    };

Blockly.Blocks.ruilong_PCF8574T_READ = {
  init: function() {
    this.setColour(Blockly.Msg['RUILONG_HUE']);
    this.appendDummyInput("").appendField("读取PCF8574T 扩展I/O");
    this.appendDummyInput("").appendField(new Blockly.FieldDropdown([["P0", "0"],["P1", "1"],["P2", "2"],["P3", "3"], 
      ["P4", "4"],["P5", "5"],["P6", "6"],["P7", "7"]]), 'CH');
    this.setOutput(true, Boolean);
    this.setInputsInline(true);
    this.setTooltip('');
  }
};
    
Blockly.Blocks.ruilong_PCF8574T_WRITE = {
    init: function () {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
         this.appendDummyInput("").appendField("设置PCF8574T 扩展I/O");
        this.appendDummyInput("").appendField(new Blockly.FieldDropdown([["P0", "0"],["P1", "1"],["P2", "2"],["P3", "3"], 
         ["P4", "4"],["P5", "5"],["P6", "6"],["P7", "7"]]), 'CH');
        this.appendValueInput("STAT")
            .appendField(Blockly.Msg.MIXLY_STAT)
            .setCheck([Number, Boolean]);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setInputsInline(true);
        this.setTooltip(Blockly.Msg.LANG_INOUT_DIGITAL_WRITE_TOOLTIP);
        this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#id2");
        this.wiki = {
            'zh-hans': {
                page: ['Arduino AVR', '输入输出', '数字输出']
            }
        };
    }
};
Blockly.Blocks.ruilong_FPM383_ED_ID = {
       init: function() {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
        this.appendDummyInput("").appendField("指纹传感器");
        this.appendValueInput("RXPIN", Number).appendField("接收(R)"+Blockly.Msg.MIXLY_PIN).setCheck(Number);
        this.appendValueInput("TXPIN", Number).appendField("发送(T)"+Blockly.Msg.MIXLY_PIN).setCheck(Number);
        this.appendValueInput("ID_NO.", Number)
            .appendField(new Blockly.FieldDropdown([["注册"," fpm.enroll"],
                                                    ["删除"," fpm.deleteID"]]), "MODE")
            .appendField(" ID ").setCheck(Number);
        this.appendDummyInput("").appendField("并返回状态");
        this.setInputsInline(true);
        //this.setPreviousStatement(true, null);
        //this.setNextStatement(true, null);
        this.setOutput(true, Number);
        this.setTooltip("ID数值范围0~49");
        this.setHelpUrl();
    }
};

Blockly.Blocks.ruilong_FPM383_EMPTY = {
    init: function() {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
        this.appendDummyInput("").appendField("指纹传感器");
        this.appendValueInput("RXPIN", Number).appendField("接收(R)"+Blockly.Msg.MIXLY_PIN).setCheck(Number);
        this.appendValueInput("TXPIN", Number).appendField("发送(T)"+Blockly.Msg.MIXLY_PIN).setCheck(Number);
        this.appendDummyInput("").appendField("清空指纹 并返回状态");
        this.setInputsInline(true);
        //this.setPreviousStatement(true, null);
        //this.setNextStatement(true, null);
        this.setOutput(true, Number);
        this.setTooltip("ID数值范围0~49");
        this.setHelpUrl();
    }
};

Blockly.Blocks.ruilong_FPM383_IDENTIFY = {
   init: function() {
    this.setColour(Blockly.Msg['RUILONG_HUE']);
    this.appendDummyInput("").appendField("指纹传感器");
    this.appendValueInput("RXPIN", Number).appendField("接收(R)"+Blockly.Msg.MIXLY_PIN).setCheck(Number);
    this.appendValueInput("TXPIN", Number).appendField("发送(T)"+Blockly.Msg.MIXLY_PIN).setCheck(Number);
    this.appendDummyInput("").appendField("获取识别ID号");
    this.setInputsInline(true);
    this.setOutput(true, Number);
    this.setTooltip("ID数值范围0~49");
    this.setHelpUrl();
    }
};


Blockly.Blocks.ruilong_FPM383_INQUIRY = {
    init: function() {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
        this.appendDummyInput("").appendField("指纹传感器");
        this.appendValueInput("RXPIN", Number).appendField("接收(R)"+Blockly.Msg.MIXLY_PIN).setCheck(Number);
        this.appendValueInput("TXPIN", Number).appendField("发送(T)"+Blockly.Msg.MIXLY_PIN).setCheck(Number);
        this.appendDummyInput("").appendField("查询已注册指纹数量");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("ID数值范围0~49");
        this.setHelpUrl();
    }
};  

Blockly.Blocks.ruilong_RS485_FSFX_INIT = {
    init: function() {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
        this.appendDummyInput("").appendField("风速风向传感器");
        this.appendValueInput("RXPIN", Number).appendField("接收(R)"+Blockly.Msg.MIXLY_PIN).setCheck(Number);
        this.appendValueInput("TXPIN", Number).appendField("发送(T)"+Blockly.Msg.MIXLY_PIN).setCheck(Number);
        this.appendDummyInput("").appendField("初始化");
        this.setInputsInline(true);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setTooltip("");
        this.setHelpUrl();
    }
};

Blockly.Blocks.ruilong_RS485_FSFX_REQUESTFS = {
    init: function() {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
        this.appendDummyInput("").appendField("风速传感器请求数据");
        this.setInputsInline(true);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setTooltip("");
        this.setHelpUrl();
    }
};
Blockly.Blocks.ruilong_RS485_FSFX_READFS = {
    init: function() {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
        this.appendDummyInput("").appendField("风速传感器 检测到风速值(m/s)");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("");
        this.setHelpUrl();
    }
};
Blockly.Blocks.ruilong_RS485_FSFX_READFS_LEVEL = {
    init: function() {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
        this.appendDummyInput("").appendField("风速传感器 检测到风速等级");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("");
        this.setHelpUrl();
    }
};
Blockly.Blocks.ruilong_RS485_FSFX_REQUESTFX = {
    init: function() {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
        this.appendDummyInput("").appendField("风向传感器请求数据");
        this.setInputsInline(true);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setTooltip("");
        this.setHelpUrl();
    }
};
Blockly.Blocks.ruilong_RS485_FSFX_READFX = {
    init: function() {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
        this.appendDummyInput("").appendField("风向传感器 检测到风向(°)");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("");
        this.setHelpUrl();
    }
};
Blockly.Blocks.ruilong_RS485_FSFX_READFX_DIR = {
    init: function() {
        this.setColour(Blockly.Msg['RUILONG_HUE']);
        this.appendDummyInput("")
                .appendField("风向传感器 检测到风向为")
                .appendField(new Blockly.FieldDropdown([["北风", "0"], 
                ["东北风", "1"],
                ["东风", "2"],
                ["东南风", "3"],
                ["南风", "4"],
                ["西南风", "5"],
                ["西风", "6"],
                ["西北风", "7"]]),'DIR')
                .appendField("状态");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("");
        this.setHelpUrl();
    }
};  

})();